package com.qk.management.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @Author ZgYn
 * @Date 2025/10/17 11:13
 * @Name TimeCountAspect
 */
@Slf4j
@Aspect
@Component
public class TimeCountAspect {

//    @Pointcut("execution(* com.qk.management.service.*.*(..))")
    public void pc(){

    }
//    @Around("pc()")
    public Object timeCount(ProceedingJoinPoint pjp) throws Throwable {

        long startTime = System.currentTimeMillis();
        Object proceed = pjp.proceed();
        long endTime = System.currentTimeMillis();
        //获取类名
        String className = pjp.getTarget().getClass().getName();
        //获取方法名
        String methodName = pjp.getSignature().getName();
        log.info("{} 执行时间: {}ms", className + "." + methodName, endTime - startTime);
        return proceed;
    }
}
